const listToTree = (list, parent = null) => {
  return list
    .filter((item) => item.parent === parent)
    .map((item) => {
      let children = listToTree(list, item.id);
      if (children.length > 0) {
        return {
          ...item,
          children,
        };
      } else {
        return {
          ...item,
        };
      }
    });
};
const deepClone = (source) => {
  console.log(source);
  const targetObj = source.constructor === Array ? [] : {};
  for (let keys in source) {
    if (source.hasOwnProperty(keys)) {
      if (source[keys] && typeof source[keys] === "object") {
        targetObj[keys] = deepClone(source[keys]);
      } else {
        targetObj[keys] = source[keys];
      }
    }
  }
  return targetObj;
};
export { listToTree ,deepClone};
